"""
情感和事件识别：如果需要情感识别能力（包括高兴<HAPPY>、伤心<SAD>、生气<ANGRY>和中性<NEUTRAL>）
和4种常见音频事件识别（包括背景音乐<BGM>、说话声<Speech>、掌声<Applause>和笑声<Laughter>），请选择SenseVoice语音识别模型。
"""
import json
from urllib import request
from http import HTTPStatus

import dashscope

# 若没有将API Key配置到环境变量中，需将下面这行代码注释放开，并将apiKey替换为自己的API Key
# dashscope.api_key = "apiKey"

task_response = dashscope.audio.asr.Transcription.async_call(
    model='sensevoice-v1',
    file_urls=[
        'https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/sensevoice/rich_text_example_1.wav'],
    language_hints=['en'],)

transcription_response = dashscope.audio.asr.Transcription.wait(
    task=task_response.output.task_id)

if transcription_response.status_code == HTTPStatus.OK:
    for transcription in transcription_response.output['results']:
        url = transcription['transcription_url']
        result = json.loads(request.urlopen(url).read().decode('utf8'))
        print(json.dumps(result, indent=4, ensure_ascii=False))
    print('transcription done!')
else:
    print('Error: ', transcription_response.output.message)